@ECHO OFF

:: Unit Test Library
:: Used to test and performance characteristics of MathLibrary.cmd
:: Author: David Colborne

:: Note - script assumes it's in the same directory as MathLibrary.cmd
:: Accepts (optionally) the following arguments:
:: %1 - Operator to be tested (+, -, *, /, com)

IF [%1]==[] (
	SET _Test=ALL
) ELSE SET _Test=%1

IF %_Test%==+ (
	ECHO:Testing addition operations...
	CALL :TestAdd
	GOTO :EOF
)

IF %_Test%==- (
	ECHO:Testing subtraction operations...
	CALL :TestSubtract
	GOTO :EOF
)

IF %_Test%==* (
	ECHO:Testing multiplication operations...
	CALL :TestMultiply
	GOTO :EOF
)

IF %_Test%==/ (
	ECHO:Testing division operations...
	CALL :TestDivide
	GOTO :EOF
)

IF %_Test%==com (
	ECHO:Testing comparison operations...
	CALL :TestCompare
	GOTO :EOF
)

IF %_Test%==COM	(
	ECHO:Testing comparison operations...
	CALL :TestCompare
	GOTO :EOF
)

IF %_Test%==ALL (
	ECHO:Testing all operations...
	CALL :TestAdd
	CALL :TestSubtract
	CALL :TestMultiply
	CALL :TestDivide
	CALL :TestCompare
	GOTO :EOF
)

IF %_Test%==all (
	ECHO:Testing all operations...
	CALL :TestAdd
	CALL :TestSubtract
	CALL :TestMultiply
	CALL :TestDivide
	CALL :TestCompare
	CALL :EOF
)

IF %_Test%==? CALL :TestHelp&GOTO :EOF
IF %_Test%==/? CALL :TestHelp&GOTO :EOF

ECHO:Invalid test type chosen.
CALL :TestHelp
GOTO :EOF

:TestHelp

	ECHO:UnitTest.cmd - Tests performance and accuracy of MathLibrary.cmd
	ECHO.
	ECHO:UnitTest.cmd [operator]
	ECHO.
	ECHO:[operator]
	ECHO:	Specifies operation to be tested:
	ECHO:		+		Addition
	ECHO:		-		Subtraction
	ECHO:		*		Multiplication
	ECHO:		/		Division
	ECHO:		com		Comparison
	ECHO:		all		Test all operations
	ECHO:		? or /?		Shows this help screen
	ECHO.
	ECHO:	If no operator is provided, UnitTest.cmd defaults to testing all operations.
	ECHO.
	ECHO:When run, UnitTest.cmd will output data in a space-delimited table with the 
	ECHO:following format:
	ECHO:	TestID Success/Fail EndTime StartTime ElapsedTime
	ECHO.
	ECHO:Example:
	ECHO:	+01 OK 21:01:50.42 21:01:50.32 0:0:0.10
	ECHO.
	ECHO:Which means:
	ECHO:	Test +01 ran successfully (OK), was started at 21:01:50.32, finished at 
	ECHO:	21:01:50.42, and took 0.10 seconds to complete.
	ECHO.
	ECHO:If a test is unsuccessful, the Success/Fail flag will will return NO, which
	ECHO:means the test did not return the expected output. 

GOTO :EOF

:TestAdd
	:: ****************************************
	:: Identical Integers - Addition - No Carry
	:: ****************************************
	CALL :UnitTest +01 14320 + 14320 28640
	CALL :UnitTest +02 1343203012423410 + 1343203012423410 2686406024846820
	CALL :UnitTest +03 34210342122433012334010234230142403423012413420124 + 34210342122433012334010234230142403423012413420124 68420684244866024668020468460284806846024826840248
	CALL :UnitTest +04 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 + 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 8642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024
	CALL :UnitTest +05 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 + 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 86420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024864202864268402464488602660426844602684024684660246606884220624688640246846460248646882460024686402486420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024
	
	:: ******************************************
	:: First integer larger with carry - Addition 
	:: ******************************************
	CALL :UnitTest +06 19 + 2 21
	CALL :UnitTest +07 5814576843 + 25608745 5840185588
	CALL :UnitTest +08 25409217129069321651971429773286662130326080315480 + 3027322471484751181930517890249552613410435 25409220156391793136722611703804552379878693725915
	CALL :UnitTest +09 1105820660299981393823938745290181607011828130652371325410528582910682205581581204581435522828487632 + 18788305185440222281854329774172957776124472367443722738221935 1105820660299981393823938745290181607030616435837811547692382912684855163357705676948879245566709567
	CALL :UnitTest +10 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685398713584 + 85435762 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685484149346
	
	:: *******************************************
	:: Second integer larger with carry - Addition 
	:: *******************************************
	CALL :UnitTest +11 2 + 19 21
	CALL :UnitTest +12 25608745 + 5814576843 5840185588
	CALL :UnitTest +13 3027322471484751181930517890249552613410435 + 25409217129069321651971429773286662130326080315480 25409220156391793136722611703804552379878693725915
	CALL :UnitTest +14 18788305185440222281854329774172957776124472367443722738221935 + 1105820660299981393823938745290181607011828130652371325410528582910682205581581204581435522828487632 1105820660299981393823938745290181607030616435837811547692382912684855163357705676948879245566709567
	CALL :UnitTest +15 85435762 + 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685398713584 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685484149346
	
	:: ***************************
	:: Identical Floats - Addition
	:: ***************************
	CALL :UnitTest +16 1.1 + 1.1 2.2
	CALL :UnitTest +17 14.320 + 14.320 28.640
	CALL :UnitTest +18 1343203.012423410 + 1343203.012423410 2686406.024846820
	CALL :UnitTest +19 432101432134201232244301330213.4223013420123423301233034421103123443201234232301243234412300123432012 + 432101432134201232244301330213.4223013420123423301233034421103123443201234232301243234412300123432012 864202864268402464488602660426.8446026840246846602466068842206246886402468464602486468824600246864024
	CALL :UnitTest +20 43210143213420123224430133021342230134201234233012.330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 + 43210143213420123224430133021342230134201234233012.330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 86420286426840246448860266042684460268402468466024.660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024864202864268402464488602660426844602684024684660246606884220624688640246846460248646882460024686402486420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024

GOTO :EOF

:TestSubtract
	:: ********************************
	:: Identical Integers - Subtraction
	:: ********************************
	CALL :UnitTest -01 14320 - 14320 0
	CALL :UnitTest -02 1343203012423410 - 1343203012423410 0
	CALL :UnitTest -03 34210342122433012334010234230142403423012413420124 - 34210342122433012334010234230142403423012413420124 0
	CALL :UnitTest -04 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 - 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 0
	CALL :UnitTest -05 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 - 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 0

	:: *********************************************
	:: First integer larger with carry - Subtraction 
	:: *********************************************
	CALL :UnitTest -06 11 - 2 9
	CALL :UnitTest -07 5814576843 - 25608745 5788968098
	CALL :UnitTest -08 25409217129069321651971429773286662130326080315480 - 3027322471484751181930517890249552613410435 25409214101746850167220247842768771880773466905045
	CALL :UnitTest -09 1105820660299981393823938745290181607011828130652371325410528582910682205581581204581435522828487632 - 18788305185440222281854329774172957776124472367443722738221935 1105820660299981393823938745290181606993039825466931103128674253136509247805456732213991800090265697
	CALL :UnitTest -10 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685398713584 - 85435762 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685313277822
	
	:: *************************************************************
	:: Second integer larger with carry - Subtraction
	:: This confirms that ExtSubtract is returning negative numbers.
	:: *************************************************************
	CALL :UnitTest -11 2 - 11 -9
	CALL :UnitTest -12 25608745 - 5814576843 -5788968098
	CALL :UnitTest -13 3027322471484751181930517890249552613410435 - 25409217129069321651971429773286662130326080315480 -25409214101746850167220247842768771880773466905045
	CALL :UnitTest -14 18788305185440222281854329774172957776124472367443722738221935 - 1105820660299981393823938745290181607011828130652371325410528582910682205581581204581435522828487632 -1105820660299981393823938745290181606993039825466931103128674253136509247805456732213991800090265697
	CALL :UnitTest -15 85435762 - 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685398713584 -2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685313277822
	
	:: ******************************
	:: Identical Floats - Subtraction
	:: ******************************
	CALL :UnitTest -16 0.2 - 0.2 0
	CALL :UnitTest -17 14.320 - 14.320 0
	CALL :UnitTest -18 3421034212243301233401.0234230142403423012413420124 - 3421034212243301233401.0234230142403423012413420124 0
	CALL :UnitTest -19 432101432134201232244301330213422301342012342330123.3034421103123443201234232301243234412300123432012 - 432101432134201232244301330213422301342012342330123.3034421103123443201234232301243234412300123432012 0
	CALL :UnitTest -20 43210143213420123224430133021342230134201234233012.330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 - 43210143213420123224430133021342230134201234233012.330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 0
	
GOTO :EOF

:TestMultiply
:: ***********************************
:: Identical Integers - Multiplication
:: ***********************************
	CALL :UnitTest *01 14320 * 14320 205062400
	CALL :UnitTest *02 1343203012423410 * 1343203012423410 1804194332583323318801116028100
	CALL :UnitTest *03 34210342122433012334010234230142403423012413420124 * 34210342122433012334010234230142403423012413420124 1170347508133914463063259198206458802412958517167295315897085703017310923645073743461903174928175376
	CALL :UnitTest *04 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 * 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 18671164765242771327586432798533818710868144126183521589220726512502766143597802610264896045562027767221204174249504603274797160449631907555256583614565060429967378508279362076339795668330661586368144
	CALL :UnitTest *05 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320123 * 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320123 1867116476524277132758643279853381871086814412618352158922072651250276614359780261026489604556202776981381276705471199674060514173016571560733063759530488108262925257420010261572054160897804166042735129
	
	:: ************************************************
	:: First integer larger with carry - Multiplication
	:: ************************************************
	CALL :UnitTest *06 11 * 2 22
	CALL :UnitTest *07 5814576843 * 25608745 148904015655292035
	CALL :UnitTest *08 25409217129069321651971429773286662130326080315480 * 3027322471484751181930517890249552613410435 76921893997666812788985465020165548739176353897305313643260289760680914993436283123524033800
	CALL :UnitTest *09 1105820660299981393823938745290181607011828130652371325410528582910682205581581204581435522828487632 * 18788305185440222281854329774172957776124472367443722738221935 20776496046081070971384754773694521202055675551734290562610622368944213462501611018406956843841661994437058074315661973217950491820531761383963873229116818607920
	CALL :UnitTest *10 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685398713584 * 85435762 174265888511536485575161788275391751483139930308148007884938057501307153679560948666202195353736887515447894661372107040390218420060931768641224426564443288961170716235291782659159222991368868791008
	
	:: *************************************************
	:: Second integer larger with carry - Multiplication 
	:: *************************************************
	CALL :UnitTest *11 2 * 19 38
	CALL :UnitTest *12 25608745 * 5814576843 148904015655292035
	CALL :UnitTest *13 3027322471484751181930517890249552613410435 * 25409217129069321651971429773286662130326080315480 76921893997666812788985465020165548739176353897305313643260289760680914993436283123524033800
	CALL :UnitTest *14 18788305185440222281854329774172957776124472367443722738221935 * 1105820660299981393823938745290181607011828130652371325410528582910682205581581204581435522828487632 20776496046081070971384754773694521202055675551734290562610622368944213462501611018406956843841661994437058074315661973217950491820531761383963873229116818607920
	CALL :UnitTest *15 85435762 * 2039730019749065801919830577216502750723285294841146356076721800658922591216087575437112568314623184556461200186546086408057300642568527318117961265031419617480215325232211104515685398713584 174265888511536485575161788275391751483139930308148007884938057501307153679560948666202195353736887515447894661372107040390218420060931768641224426564443288961170716235291782659159222991368868791008
	
	:: *********************************
	:: Identical Floats - Multiplication
	:: *********************************
	CALL :UnitTest *16 0.2 * 0.2 0.04
	CALL :UnitTest *17 14.320 * 14.320 205.062400
	CALL :UnitTest *18 13432030.12423410 * 13432030.12423410 180419433258332.3318801116028100
	CALL :UnitTest *19 432101432134201232244301330213422301342012342330123303442110.3123443201234232301243234412300123432012 * 432101432134201232244301330213422301342012342330123303442110.3123443201234232301243234412300123432012 186711647652427713275864327985338187108681441261835215892207265125027661435978026102648960455620277672212041742495046032.74797160449631907555256583614565060429967378508279362076339795668330661586368144
	CALL :UnitTest *20 432101432134201232244301330213422301342012342330123303442110.31234432012342323012432344123001234320123 * 432101432134201232244301330213422301342012342330123303442110.31234432012342323012432344123001234320123 186711647652427713275864327985338187108681441261835215892207265125027661435978026102648960455620277698138127670547119967.4060514173016571560733063759530488108262925257420010261572054160897804166042735129

GOTO :EOF

:TestDivide
	:: ***********************************
	:: Identical Integers - Division
	:: ***********************************
	CALL :UnitTest /01 2 / 2 1
	CALL :UnitTest /02 11 / 11 1
	CALL :UnitTest /03 141 / 141 1
	CALL :UnitTest /04 2431 / 2431 1
	CALL :UnitTest /05 14320 / 14320 1
	CALL :UnitTest /06 2134031021 / 2134031021 1
	CALL :UnitTest /07 1343203012423410 / 1343203012423410 1
	CALL :UnitTest /08 34210342122433012334010234230142403423012413420124 / 34210342122433012334010234230142403423012413420124 1
	CALL :UnitTest /09 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 / 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 1
	CALL :UnitTest /10 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320123 / 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320123 1
	
	:: ***********************************
	:: Whole Positive Integer Answers - Division
	:: ***********************************
	CALL :UnitTest /11 28640 / 14320 2
	CALL :UnitTest /12 2686406024846820 / 1343203012423410 2
	CALL :UnitTest /13 68420684244866024668020468460284806846024826840248 / 34210342122433012334010234230142403423012413420124 2
	CALL :UnitTest /14 8642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024 / 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 2
	CALL :UnitTest /15 86420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024864202864268402464488602660426844602684024684660246606884220624688640246846460248646882460024686402486420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024 / 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 2
	
	:: **********************************
	:: Whole Positive Integer - Reflexive
	:: **********************************
	CALL :UnitTest /16 28640 / 2 14320
	CALL :UnitTest /17 2686406024846820 / 2 1343203012423410
	CALL :UnitTest /18 68420684244866024668020468460284806846024826840248 / 2 34210342122433012334010234230142403423012413420124
	CALL :UnitTest /19 8642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024 / 2 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012
	CALL :UnitTest /20 86420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024864202864268402464488602660426844602684024684660246606884220624688640246846460248646882460024686402486420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024 / 2 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012
	
	:: **********************************
	:: Finite Floating Point
	:: **********************************
	CALL :UnitTest /21 14320 / 28640 0.5
	CALL :UnitTest /22 1343203012423410 / 2686406024846820 0.5
	CALL :UnitTest /23 34210342122433012334010234230142403423012413420124 / 68420684244866024668020468460284806846024826840248 0.5
	CALL :UnitTest /24 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 / 8642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024 0.5
	CALL :UnitTest /25 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 / 86420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024864202864268402464488602660426844602684024684660246606884220624688640246846460248646882460024686402486420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024 0.5
	
	:: **********************************
	:: Reflexive Floating Point
	:: **********************************
	CALL :UnitTest /26 14320 / 0.5 28640
	CALL :UnitTest /27 1343203012423410 / 0.5 2686406024846820
	CALL :UnitTest /28 34210342122433012334010234230142403423012413420124 / 0.5 68420684244866024668020468460284806846024826840248
	CALL :UnitTest /29 4321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 / 0.5 8642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024
	CALL :UnitTest /30 43210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012432101432134201232244301330213422301342012342330123303442110312344320123423230124323441230012343201243210143213420123224430133021342230134201234233012330344211031234432012342323012432344123001234320124321014321342012322443013302134223013420123423301233034421103123443201234232301243234412300123432012 / 0.5 86420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024864202864268402464488602660426844602684024684660246606884220624688640246846460248646882460024686402486420286426840246448860266042684460268402468466024660688422062468864024684646024864688246002468640248642028642684024644886026604268446026840246846602466068842206246886402468464602486468824600246864024
	
GOTO :EOF

:TestCompare
	ECHO:No tests at this time...
GOTO :EOF


:UnitTest
	SETLOCAL EnableDelayedExpansion
	
	SET _TestID=%1
	SET _Num1=%2
	SET _Op=%3
	SET _Num2=%4
	SET _UnitResult=
	SET _DesiredResult=%5
	SET _TimeElapsed=
	
	SET _TimeStart=!time!
	CALL MathLibrary.cmd %_Num1% %_Op% %_Num2% _UnitResult
	SET _TimeEnd=!time!
	
	CALL :CalcTime %_TimeStart% %_TimeEnd% _TimeElapsed
	
	IF %_UnitResult%==%_DesiredResult% (
		ECHO:%_TestID% OK %_TimeEnd% %_TimeStart% %_TimeElapsed%
	) ELSE (
		ECHO:%_TestID% NO %_TimeEnd% %_TimeStart% %_TimeElapsed%
	)
	
GOTO :EOF

:CalcTime
	SETLOCAL EnableDelayedExpansion
	:: Calculates time elapsed between two given times.
	:: Assumes US location/time format
	:: Accepts three parameters:
	:: %1, %2 - Start, End times (passed by value)
	:: %3 - Time delta (returned by reference)
	::
	:: Example invocation:
	:: CALL :CalcTime 12:00:00.00 12:30:00.00 _Elapsed
	:: |--> Returns 00:30:00.00 in _Elapsed
	
	SET _Time1=%1
	SET _Time2=%2
	
	FOR /F "tokens=1-4 delims=:." %%G IN ("%_Time2%") DO (
		SET _HEnd=%%G
		SET _MEnd=%%H
		SET _SEnd=%%I
		SET _mSEnd=%%J
	)

	FOR /F "tokens=1-4 delims=:." %%K IN ("%_Time1%") DO (
		SET _HStart=%%K
		SET _MStart=%%L
		SET _SStart=%%M
		SET _mSStart=%%N
	)
	
	:: Get leading 0 out - if we don't, CMD will think we're doing math against
	:: an improperly formatted octal number and behave erratically.
	IF %_HEnd:~0,1% EQU 0 (
		SET _HEnd=%_HEnd:~1,1%
	)
	IF %_MEnd:~0,1% EQU 0 (
		SET _MEnd=%_MEnd:~1,1%
	)
	IF %_SEnd:~0,1% EQU 0 (
		SET _SEnd=%_SEnd:~1,1%
	)
	IF %_mSEnd:~0,1% EQU 0 (
		SET _mSEnd=%_mSEnd:~1,1%
	)
	
	IF %_HStart:~0,1% EQU 0 (
		SET _HStart=%_HStart:~1,1%
	)
	IF %_MStart:~0,1% EQU 0 (
		SET _MStart=%_MStart:~1,1%
	)
	IF %_SStart:~0,1% EQU 0 (
		SET _SStart=%_SStart:~1,1%
	)
	IF %_mSStart:~0,1% EQU 0 (
		SET _mSStart=%_mSStart:~1,1%
	)
	
	SET _mSElapsed=
	SET _SElapsed=
	SET _MElapsed=
	SET _HElapsed=
	SET _TimeElapsed=

	SET /A _mSElapsed=_mSEnd-_mSStart
	IF %_mSElapsed% LSS 0 (
		SET /A _SElapsed=-1
		SET /A _mSElapsed+=100
	)
	
	SET /A _SElapsed=_SEnd-_SStart+_SElapsed
	IF %_SElapsed% LSS 0 (
		SET /A _MElapsed=-1
		SET /A _SElapsed+=60
	)
	
	SET /A _MElapsed=_MEnd-_MStart+_MElapsed
	IF %_MElapsed% LSS 0 (
		SET /A _HElapsed=-1
		SET /A _MElapsed+=60
	)
	
	SET /A _HElapsed=_HEnd-_HStart+_HElapsed
	IF %_HElapsed% LSS 0 (
		SET /A _HElapsed+=24
	)
	
	SET _TimeElapsed=%_HElapsed%:%_MElapsed%:%_SElapsed%.%_mSElapsed%
	
	ENDLOCAL & SET %3=%_TimeElapsed%
GOTO :EOF